package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.sql.Array;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result page(EmpQueryParam empQueryParam) {
        log.info("查询请求参数： {}", empQueryParam);
        PageResult  pageResult = empService.page(empQueryParam);

        return Result.success(pageResult);
    }

    @DeleteMapping()
    public Result delete(@RequestParam Integer[] ids){
        //log.info("批量删除部门: ids={}" ,Arrays.asList(ids));
         empService.delete(ids);
        return Result.success();
    }

    @PostMapping()
    public Result addEmp(@RequestBody Emp emp){
        empService.addEmp(emp);
        return Result.success();
    }

    //查询回显
    @GetMapping("{id}")
    public Result getInfo(@PathVariable Integer id){
       Emp emp = empService.getInfo(id);
       return Result.success(emp);
    }
}
